home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: C beginner needs your help ASAP
- Date: Mon, 19 Feb 96 01:28:33 GMT
- Organization: none
- Distribution: world
- Message-ID: <824693313snz@genesis.demon.co.uk>
- References: <4g862f$p0b@risky.ecs.umass.edu> <4g8ahd$p8b@spectator.cris.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4g8ahd$p8b@spectator.cris.com>
- aubrey@concentric.net "Aubrey Harrison" writes:
-
- >In article <4g862f$p0b@risky.ecs.umass.edu>, sebag@ecs.umass.edu says...
- >>
- >>I am a new C programmmer who desperately needs help.
- >>I have been digging in the manuals for a way to do this but have still
- >>come out empty handed. Here is the problem: I want to open files in a while
- >>loop with different filenames. data0,data1,data2,data3, .. data1000 , ...
-
- ...
-
- > sprintf(buf,"%d",i);
- > strcpy( filename,"data");
- > strcat( filename, buf );
- > strcat( filename, ".ext");
-
-
- Can can replace these 4 lines with:
-
- sprintf(filename, "data%d.ext", i);
-
- (you'd scrap the .ext to match the spec).
-
- sprintf is a very powerful function, for example
-
- sprintf(filename, "data%03d", i);
-
- can generate filenames of the form data000,data001,data002,...,data999 which
- is often preferable (e.g. for sorted directory listings).
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-